package org.zero.orika.converter;

import lombok.SneakyThrows;
import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;
import org.zero.model.constant.GenderEnum;
import org.zero.util.EnumUtils;

/**
 * @author Zero (cnzeropro@qq.com)
 * @date 2021/9/1 15:44
 */
public class GenderConverter extends BidirectionalConverter<Byte, GenderEnum> {

    @SneakyThrows
    @Override
    public GenderEnum convertTo(Byte source, Type<GenderEnum> destinationType, MappingContext mappingContext) {
        return EnumUtils.getEnum(GenderEnum.class, source);

    }

    @Override
    public Byte convertFrom(GenderEnum source, Type<Byte> destinationType, MappingContext mappingContext) {
        return EnumUtils.getKey(source, Byte.class);
    }
}